$(function () {
    $("#buy").click(function () {
        var num = $("#buyNum").val();
        var surplus = $("#surplus").text();
        if (num==""){
            alert("购买数量不能为空");
            $("#sumprice").text("0.0");
        }else if (!(/^[0-9]*[1-9][0-9]*$/.test(num))){
            alert("购买数量必须为正整数");
            $("#sumprice").text("0.0");
        }else if (num>surplus){
            alert("购买数量不能超过剩余数量");
            $("#sumprice").text("0.0");
        }else {
            var sumprice = $("#price").text()*num;
            $("#sumprice").text(sumprice);
            $("#fm").submit();
        }
    })
})